package git.bankview.wl.report;

import java.util.*;
import java.text.*;
import java.io.*;

import laya.semi.process.*;
import git.bankview.sl.report.ReportCommon;

import git.bankview.sl.db.*;

import org.apache.log4j.Logger;

public class AccessoriesGetter
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(AccessoriesGetter.class);

	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] params = oCtx.getActivityParameter().split(":");
		String oAccField = params[0];
		String oAccNameField = params[1];
		String oMainObjName = params[2];
		String oTransid = (String)oCtx.getField("transid");
		
		File dir = new File(ReportCommon.JASPER_DIR + oTransid);
		if (dir.exists())
		{
			File[] v = dir.listFiles();
			File[] vAccessory = new File[v.length - 1];
			String[] vAccessoryName = new String[v.length - 1];
			int nAcIdx = -1;
			
			for (int i = 0; i < v.length; ++i)
			{
				if (!oMainObjName.equalsIgnoreCase(v[i].getName()))
				{
					vAccessory[++nAcIdx] = v[i];
					vAccessoryName[nAcIdx] = v[i].getName();
				}
			}
		
			oCtx.setField(oAccField, vAccessory);
			oCtx.setField(oAccNameField, vAccessoryName);
		}
	}
}
